#include "pine.h"

static Logger::ptr g_logger = MYWEB_LOG_ROOT();

int main(int argc, char *argv[]) {
    SetThreadName("main_thread");

    MYWEB_LOG_FATAL(g_logger) << "fatal msg";
    MYWEB_LOG_ERROR(g_logger) << "err msg";
    MYWEB_LOG_INFO(g_logger) << "info msg";
    MYWEB_LOG_DEBUG(g_logger) << "debug msg";

    MYWEB_LOG_FMT_FATAL(g_logger, "fatal %s:%d", __FILE__, __LINE__);
    MYWEB_LOG_FMT_ERROR(g_logger, "err %s:%d", __FILE__, __LINE__);
    MYWEB_LOG_FMT_INFO(g_logger, "info %s:%d", __FILE__, __LINE__);
    MYWEB_LOG_FMT_DEBUG(g_logger, "debug %s:%d", __FILE__, __LINE__);

    SetThreadName("new_thread");

    g_logger->setLevel(LogLevel::WARN);
    MYWEB_LOG_FATAL(g_logger) << "fatal msg";
    MYWEB_LOG_ERROR(g_logger) << "err msg";
    MYWEB_LOG_INFO(g_logger) << "info msg"; // 不打印
    MYWEB_LOG_DEBUG(g_logger) << "debug msg"; // 不打印

    MYWEB_LOG_FATAL(g_logger) << "fatal msg";
    MYWEB_LOG_ERROR(g_logger) << "err msg";
    MYWEB_LOG_INFO(g_logger) << "info msg"; // 不打印
    MYWEB_LOG_DEBUG(g_logger) << "debug msg"; // 不打印

    Logger::ptr test_logger = MYWEB_LOG_NAME("test_logger");
    StdoutLogAppender::ptr appender(new StdoutLogAppender);
    LogFormatter::ptr formatter(new LogFormatter("%d{} %T%t%T%N%T[%p]%T[%c]%T%f:%l%T%m%n")); // 时间：启动毫秒数 级别 日志名称 文件名：行号 消息 换行
    appender->setFormatter(formatter);
    test_logger->addAppender(appender);
    test_logger->setLevel(LogLevel::WARN);

    MYWEB_LOG_ERROR(test_logger) << "err msg";
    MYWEB_LOG_INFO(test_logger) << "info msg"; // 不打印

    MYWEB_ASSERT2(false, "assertion error");


    return 0;
}